<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>CSS实习动态下划线</title>
	<style>
		* {
			padding: 0;
			margin: 0;
		}

		html,
		body {
			height: 100vh;
			width: 100vw;
			background-color: #f2f2f2;
			overflow: hidden;
		}

		ul {
			list-style-type: none;
			display: flex;
			justify-content: center;
		}

		li {
			position: relative;
			padding: 20px;
			font-size: 24px;
			color: #000;
			line-height: 1;
			cursor: pointer;
		}

		/* li::before {
			content: "";
			position: absolute;
			right: 100%;
			bottom: 0;
			width: 0;
			border-bottom: 2px solid #000;
			transition: 0.2s all linear;
		}

		li:hover::before {
			width: 100%;
			right: 0;
		} */

		li::before {
			content: "";
			position: absolute;
			right: 0;
			bottom: 0;
			width: 0;
			border-bottom: 2px solid #000;
			transition: 0.2s all linear;
		}

		li:hover::before {
			width: 100%;
			transition-delay: 0.1s;
		}

		li:hover~li::before {
			right: 100%;
		}
	</style>
</head>

<body>
	<ul>
		<li>标题一</li>
		<li>很较长的标题二</li>
		<li>标题三</li>
		<li>较长的标题四</li>
		<li>五</li>
	</ul>
</body>

</html>